package com.ycb.controller;

import com.ycb.entity.Goods;
import com.ycb.feign.GoodsClient;
import com.ycb.service.GoodsService;
import io.seata.core.context.RootContext;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 黄泽群
 * @since 2023-12-11
 */
@Slf4j
@RestController
@RequestMapping("/")
@RequiredArgsConstructor
public class GoodsController implements GoodsClient {

    private final GoodsService goodsService;

    @Override
    public Goods getById(Integer id) {
        return goodsService.getById(id);
    }

    @Override
    public Goods subStock(Integer id, Integer num) {
        BusinessActionContext context = BusinessActionContextUtil.getContext();
        log.warn(" GoodsController >> context :{} id:{} num:{} inGlobalTransaction:{}",context,id,num, RootContext.inGlobalTransaction());
        return goodsService.subStock(context,id,num);
    }
}
